﻿using DataBaseDAO;
using Microsoft.AspNetCore.Mvc;

namespace MyCSharpMVCProject.Controllers
{
    /// <summary>
    /// 通过Ajax请求相应数据的格式模型
    /// </summary>
    public class JsonRes
    {
        public JsonRes(ResultType resultType, string message, object data = null)
        {
            this.resultType = resultType;
            this.message = message;
            this.data = data;

        }

        public object resultType { get; set; }
        public string message { get; set; }
        public object data { get; set; }
    }

    public enum ResultType
    {
        Success = 1,
        Error = 2,
        Success_manager = 3
    }
    public class BaseController : Controller
    {
        protected ActionResult SuccessResult(string message = "操作成功！", object data = null)
        {
            return Content(new JsonRes(ResultType.Success, message, data).ToJsonCon());
        }

        protected ActionResult Success_ManagerResult(string message = "管理员操作成功！", object data = null)
        {
            return Content(new JsonRes(ResultType.Success_manager, message, data).ToJsonCon());
        }

        protected ActionResult ErrorResult(string message = "操作失败！", object data = null)
        {
            return Content(new JsonRes(ResultType.Error, message, data).ToJsonCon());
        }
    }


}
